from flask_marshmallow import base_fields
from flask_restplus_patched import ModelSchema
from app.modules.common.schemas import BaseSchema
from .models import LoginToken

from app.modules.user.schemas import UserListSchema

class BaseLoginSchema(ModelSchema):
    class Meta:
        model = LoginToken
        fields = (
            LoginToken.token_id.key,
            LoginToken.user_id.key,
            LoginToken.user_name.key,
            LoginToken.create_time.key,
            LoginToken.login_out_time.key,
            LoginToken.desc.key,
            LoginToken.login_ip.key,
        )

        dump_only = (
            LoginToken.token_id.key,
        )

class LoginSchema(BaseSchema):
    data = base_fields.Nested(
        BaseLoginSchema,
        many = False
    )
    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )

class LoginInfoSchema(BaseSchema):
    data = base_fields.Nested(
        UserListSchema,
        many = False
    )
    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )
